import request from '@/utils/http'
import { responseOrderInfoType, responseOrderStatusType, responseWeixinPayType, responseOrderListType, resOrderList } from './type'

enum API {
  // 创建订单
  ORDER_ADD_URL = '/order/orderInfo/auth/submitOrder',
  // 获取订单
  ORDER_GET_URL = '/order/orderInfo/auth/getOrderInfo',
  // 获取订单状态
  ORDER_STATUS_URL = '/order/orderInfo/auth/getStatusList',
  // 取消订单
  ORDER_CANCEL_URL = '/order/orderInfo/auth/cancelOrder',
  // 下单，生成微信支付二维码
  ORDER_WEIXIN_URL = '/order/weixin/createNative',
  // 查询微信支付订单状态
  ORDER_XWEXIN_STATUS_URL = '/order/weixin/queryPayStatus',
  // 获取订单分页列表
  ORDER_LIST_URL = '/order/orderInfo/auth',
}

/**
 * 创建订单
 *
 * @param hoscode {string} 医院编号，限流使用
 * @param scheduleId {string} 排班id
 * @param patientId {string | number} 就诊人id
 */
export const addOrderInfoAPI = (hoscode: string, scheduleId: string, patientId: string | number) => {
  return request({
    url: API.ORDER_ADD_URL + `/${hoscode}/${scheduleId}/${patientId}`,
    method: 'POST',
  })
}
/**
 * 获取订单状态
 *
 */
export const toGetOrderStatusAPI = () => {
  return request({
    url: API.ORDER_STATUS_URL,
  })
}

/**
 *  获取订单
 *
 * @param id {string | number} 订单id
 */
export const getOrderInfoAPI = (id: string | number) => {
  return request<any, responseOrderInfoType>({
    url: API.ORDER_GET_URL + `/${id}`,
  })
}

/**
 * 取消订单
 *
 * @param orderId { string | number } 订单id
 */
export const cancelOrderAPI = (orderId: string | number) => {
  return request<any, responseOrderStatusType>({
    url: API.ORDER_CANCEL_URL + `/${orderId}`,
  })
}

/**
 * 下单，生成微信二维码
 *
 * @param orderId {long} 订单id
 */
export const placeOrderToPayAPI = (orderId: string | number) => {
  return request<any, responseWeixinPayType>({
    url: API.ORDER_WEIXIN_URL + `/${orderId}`,
  })
}

/**
 * 查询微信支付订单状态
 *
 * @param orderId { lang } 订单id
 */
export const wechatPaymentStatusAPI = (orderId: number | string) => {
  return request({
    url: API.ORDER_XWEXIN_STATUS_URL + `/${orderId}`,
  })
}

/**
 * 获取订单分页列表
 *
 * @param page { number } 当前页码
 * @param limit { number } 每页记录数
 * @param params:{ object } 其他参数
 */
export const getOrderListAPI = (page: number, limit: number, params: resOrderList = {}) => {
  return request<any, responseOrderListType>({
    url: API.ORDER_LIST_URL + `/${page}/${limit}`,
    params,
  })
}
